function [p]=sortdis(M,C)
n=len(M);
P=abs(M).^2;
for i=1:n
    basis=zeros(1,n);
    basis(i)=1;
    P(i,2)=real(basis*C*(basis)');
end
p=sortrows(P,2);
p=p(:,1);
end
